setTimeout(initDoEnterKey,1000);
function initDoEnterKey(){
	if( document.onkeydown == null )document.attachEvent("onkeydown",doEnterKey);
}
function doEnterKey(){
	if( (event.keyCode == 13 || event.keyCode == 40) &&
			 event.srcElement.type != "button" &&
			 event.srcElement.tagName != "TEXTAREA"
		){
		event.cancelBubble = true;
		event.keyCode = 9;
	}
}

function findUp(el,ids){
	event.cancelBubble = true;
	if( event.ctrlKey )return;
	var tr = getParentTR(el);
	for( var a=1; a < arguments.length; a++)
		for( var i=0; i < tr.all.length; i++ )
			if( tr.all[i].id.match(arguments[a]) )
				return tr.all[i].href ? eval(tr.all[i].href.replace("javascript:","")) : tr.all[i].click();
}
function findUp_(el,ids){
	for( var a=1; a < arguments.length; a++){
		var id = arguments[a];
		for( var e = findDown(el,id); !e && el ; el=el.parentElement )
			if( (e = findDown(el,id)) ) return e;
	}
	return e;
}
function findDown(el,id){
	if( (el.id||"").match(id) )return el;
	var all = el.all;
	for( var i=0; i < all.length && !(all[i].id||"").match(id); i++ ){}
	return all[i] || null;
}
function GVX_InitHeader(dg){
	var inputs = (dg||divGrid).all.tags("INPUT");
	for( var i=0 ; i < inputs.length; i++ ){
		if( inputs[i].type != "text" )continue;
		inputs[i].onfocus = function(){
			event.srcElement.style.position = "relative";
			event.srcElement.style.borderColor = "maroon";
			event.srcElement.style.zIndex=1000;
			event.srcElement.style.backgroundColor="white";
		};
		inputs[i].onblur = function(){
			event.srcElement.style.position = "";
			event.srcElement.style.borderColor = "";
			event.srcElement.style.zIndex=null;
			event.srcElement.style.backgroundColor="";
		};
	}
}
function GVX_toggleColor(el,color){
	if( color ){
		if(!el.bc )el.bc = el.style.backgroundColor;
		el.style.backgroundColor = color;
	}else el.style.backgroundColor = el.bc
}
function GVX_toggleUnderline(el,on){
	el.style.textDecorationUnderline = on;
}
function checkAllVisible(chk){
	var inputs = getParentTR(chk).all.tags("INPUT");
	for( var i in inputs )
		if( inputs[i].type == "checkbox" )
			if( inputs[i].checked != chk.checked )inputs[i].click();
}
function GVX_showFilter(sql,filterString){
	if( !event.altKey )return;
	if( GVX_showFilter.w && !GVX_showFilter.w.closed )return;
	GVX_showFilter.w = showModelessDialog("/manager/common/filterbuilder.aspx?sql="+sql+"&filterString="+filterString,{callBack:GVX_updateFilter},"resizable:1");
}
function GVX_updateFilter(filterString){
	location.reload(location.pathname.split("?")[0]+"?Filter="+escape(filterString));
}
// Helpers
function getParentTD(el){return getParentByTag(el,"td")}
function getParentTR(el){return el.tagName=="TR"?el:getParentByTag(el,"tr")}
function getParentTBODY(el){return getParentByTag(el,"tbody")}
function getParentTable(el){return getParentByTag(el,"table")}
function getParentByTag(el,tagName){return getParentElementByTagName(el,tagName)}
function getParentElementByTagName(el,parentName){
	parentName = parentName.toLowerCase();
	for( ; el; el = el.parentElement )
		if( el.tagName.toLowerCase() == parentName )return el;
	return null;
}
